package com.generalsentiment.evaluation

import java.io.File
import java.io.PrintWriter
import scala.io.Source

// This class of tests compare how well we rank pairs of entities compared to
// some gold standard (like political polls or election results
class PairedTest(sourceFile: File) extends SentimentTest {

  private val inputLines = Source.fromFile(sourceFile).getLines
  private val goldPairs = inputLines.map(new PairExample(_))

  def makeQueries(destination: File): Unit = {
    val output = new PrintWriter(new File(destination, sourceFile.getName()))
    goldPairs.foreach(_.makeQueries(output))
    output.close()
  }
}

class PairExample(lineToParse: String) {
  private val tokens = lineToParse.split("\t")
  private val winner = tokens(0)
  private val loser  = tokens(1)
  private val date: SentimentTest.Date = Integer.parseInt(tokens(2))

  def makeQueries(output: PrintWriter): Unit = {
    output.println(winner + "\t" + loser + "\t" + date)
  }
}
